/*
ID:luongho3
LANG:C++
TASK:runround
*/
#include <iostream>
#include <fstream>
using namespace std;
#define MAX 9
ifstream fin("runround.in");
ofstream fout("runround.out");
int number[MAX];
int M;
void toArray() {
     int i = MAX - 1;
     for (;i>=0;--i) {
           number[i] = M%10;
           M /= 10;
     }
}
void increase() {
      int r = 0;
      int  i = MAX - 1;
      for (;i>=0;--i) {
          if (number[i] == 9) {
             r = 1;
             number[i] = 0;
          }
          else {
               number[i]++;
               r = 0;
               break;     
          }
      }
}
bool isRunaround() {
     int i;
     for (i=0;i<MAX;++i) {
         if (number[i] != 0) {
            break;
         }
     }
     //
     int nDigit = 0;
     int n_array[MAX];
     for (;i<MAX;++i) {
         n_array[nDigit] = number[i];
         ++nDigit;
     }
     //
     int flag[MAX];
     int c[MAX];
     for (i=0;i<MAX;++i) {
         flag[i] = 0;    
         c[i] = 0;
     }
     //
     for (i=0;i<nDigit;++i) {
         c[n_array[i]]++;   
         if (c[n_array[i]] > 1) {
            return false;
         }
         if (c[0] > 0) {
            return false;
         }   
     }
     //
     int start_pos = 0;
     int init_pos = 0;
     for (i=0;i<nDigit;++i) {
         flag[start_pos] = 1;
         int n = n_array[start_pos];
         int next_pos = (n + start_pos) % nDigit; // more here
         if (flag[next_pos] == 0) {
            start_pos = next_pos;                   
         }
         else {
              if (i < nDigit - 1) {
                 return false;     
              }
              else {
                   if (next_pos == init_pos) {
                      return true;
                   }
              }
         }
     }
     return false;
}
void printNumber() {
     int i;
     for (i=0;;++i) {
         if (number[i] != 0) {
            break;
         }
     }
     for (;i<MAX;++i) {
         fout << number[i];
     }
     fout <<"\n";
}
int main() {
    fin >> M;
    toArray();
    do {
        increase();
    } while (!isRunaround());
    printNumber();
    return 0;
}
